

using System;
using System.Collections.Generic;
using System.Text;

using SubSonic;
using System.Data;

namespace JTC.MiniCommerce.Store {

  public partial class AttributeItemController {
  
    #region Methods
    
    #region Public

    /// <summary>
    /// Fetches the selected attribute item.
    /// </summary>
    /// <param name="attributeId">The attribute id.</param>
    /// <param name="skuSuffix">The sku suffix.</param>
    /// <returns></returns>
    public AttributeItem FetchSelectedAttributeItem(int attributeId, string skuSuffix) {
      Query query = new Query(Store.AttributeItem.Schema).
        AddWhere(Store.AttributeItem.Columns.AttributeId, attributeId).
        AddWhere(Store.AttributeItem.Columns.SkuSuffix, skuSuffix);
      IDataReader reader = query.ExecuteReader();
      AttributeItemCollection attributeItemCollection = new AttributeItemCollection();
      attributeItemCollection.LoadAndCloseReader(reader);
      if(attributeItemCollection.Count > 0) {
        return attributeItemCollection[0];
      }
      else {
        return null;
      }
    }
    
    #endregion
    
    #endregion
    
  }
}
